package com.itboye.mengwu.app.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.config.GlobalConfig;
import com.itboye.core.alert.ByAlert;
import com.itboye.core.utils.SoftwareUtil;
import com.itboye.core.utils.XImageLoader;
import com.itboye.mengwu.R;
import com.itboye.mengwu.app.ui.main.PingLunBaoBeiActivity;
import com.itboye.mengwu.data.model.OrderQueryModel.OrderList;
import com.itboye.mengwu.luntan.comment.adapter.GridViewAdapter;
import com.itboye.mengwu.widget.MyGridView;

/** GirdView 数据适配器 */
public class OrderGoodsCommentAdapter extends BaseAdapter {
	Activity context;

	OrderList list;
	ArrayList<String> imgUrls;
	OnItemClickListener onitemClickListener;
	public OrderGoodsCommentAdapter(Activity _context,
			OrderList _list,ArrayList<String> imgUrls,OnItemClickListener onitemClickListener) {
		this.list = _list;
		this.context = _context;
		this.imgUrls=imgUrls;
		this.onitemClickListener=onitemClickListener;
	}

	@Override
	public int getCount() {
		return list == null ? 0 : list.getItems().size();
	}

	@Override
	public Object getItem(int position) {
		return list == null ? 0 : list.getItems().get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		if (convertView == null) {
			holder = new Holder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.goods_comment, null);
			/**
			 * item_goodscomment_nickname,item_goodscomment_introduction,
			 * item_goodscomment_goods_date
			 * ,item_goodscomment_goods_color,item_goodscomment_goods_size
			 */
			holder.goods_list_goodstv = (TextView) convertView
					.findViewById(R.id.goods_name);
			holder.old_price = (TextView) convertView
					.findViewById(R.id.goods_price);
			holder.edtcontext = (EditText) convertView
					.findViewById(R.id.edtcontext);
			holder.goods_list_image = (ImageView) convertView
					.findViewById(R.id.goods_im);
			holder.aiWuJiaGridView=(MyGridView) convertView.findViewById(R.id.aiWuJiaGridView);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		holder.goods_list_goodstv.setText(list.getItems().get(position).getName());
		holder.old_price.setText(list.getItems().get(position).getPrice());
		holder.aiWuJiaGridView.setAdapter(new GridViewAdapter(context, list.getItems().get(position).getImgUrls()));
		holder.aiWuJiaGridView.setTag(position);
		holder.aiWuJiaGridView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position2, long id) {
				// TODO Auto-generated method stub
				SoftwareUtil.showOrHideSoftware(view, context, false);
				((PingLunBaoBeiActivity)context).choosePhoto(position,position2);
			}
		});
		XImageLoader.load(GlobalConfig.API_URL + "/picture/index?id="
				+ list.getItems().get(position).getImgUrl(), holder.goods_list_image);
		return convertView;
	}

	class Holder {
		ImageView goods_list_image;
		TextView old_price,goods_list_goodstv;
		EditText edtcontext;
		MyGridView aiWuJiaGridView;
	}
}